from django.utils.deprecation import MiddlewareMixin
from web import models
from django.shortcuts import HttpResponse, redirect

class AuthMiddleware(MiddlewareMixin):
    def process_request(self, request):
        if request.path_info == "/web/loginplus/":
            return
        if request.path_info == "/web/image/":
            return
        if request.path_info == "/web/registerplus/":
            return
        if request.path_info == "/web/send/sms/":
            return
        if request.path_info == "/web/resetplus/":
            return
        if request.path_info == "/web/userexpired/":
            return
        if request.path_info == "/favicon.ico":
            return

        user_id = request.session.get('user_id', None)
        user_object = models.UserInfo.objects.filter(id=user_id).first()
        request.tracer = user_object
        if user_id:
            return
        return redirect("/web/userexpired")

